<?php
namespace app\interfaces\controller;

use think\Db;
use think\Request;
use app\interfaces\model\GoodsType;

class Sale
{

    /*
     * 用户端 - 天天特价分类列表
     */
    public function sale_type()
    {
        $result = GoodsType::where(['status' => '1', 'parenTid' => 0])->field('id,parenTid,title')->select();

        return ['code' => 200, 'message' => '成功', 'data' => recursion_node($result)];

    }

    /*
     * 用户端 - 天天特价列表
     */
    public function sale_list()
    {
        // 获取参数
        $inquire = Request::instance()->param();

        $condition['status'] = ['eq', '1'];

        if (!empty($inquire['parenTid'])) $condition['goods_str'] = ['like', '%,' . $inquire['parenTid'] . ',%'];

        $result = Db::view('group_goods', 'goods_id,price as sale_price,status')
            ->view('shop_goods', 'title,price,thumb_img,sale_number,rebate_percentage,goods_str', 'group_goods.goods_id = shop_goods.id')
            ->where($condition)
            ->paginate(10);

        return ['code' => 200, 'message' => '成功', 'data' => $result];


    }

}
